import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:toast/toast.dart';

class CupertinoNavigatorDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'IOS组件集合',
      home: CupertinoTabScaffold(
          tabBar: CupertinoTabBar(items: [
            BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('首页')),
            BottomNavigationBarItem(icon: Icon(Icons.chat), title: Text('聊天'))
          ]),
          tabBuilder: (context, index) {
            return CupertinoTabView(
              builder: (context) {
                switch (index) {
                  case 0:
                    return HomePage();
                    break;
                  case 1:
                    return ChatPage();
                    break;
                }
              },
            );
          }),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: CupertinoNavigationBar(
        middle: Text('Home'),
      ),
      child: Text('Home'),
    );
  }
}

class ChatPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: CupertinoNavigationBar(
        leading: FlatButton(
            shape: CircleBorder(
                side: BorderSide(
                    color: Colors.green, width: 5, style: BorderStyle.solid)),
            onPressed: () {
              Toast.show('返回', context);
            },
            child: Icon(CupertinoIcons.back)),
        middle: Text('Chat'),
        trailing: Icon(CupertinoIcons.add),
      ),
      child: Text('Chat'),
    );
  }
}
